% T = RS_ENCODER(DATA) Given a data sequence, encode a Reed-Solomon code 
%                      word.
%
%  Input
%         DATA  Data word to be encoded
%
%  Output
%         T    Code word to be transmitted
%
%  Notes
%
%  The values of t and m are specified as global variables in init.m

function T = RS_encoder(data)
    global t m n k g

    % The data symbols are the coefficients of the message polynomial
    M = fliplr(data);

    % Form x^(n-k)
    xnmk = [-1*ones(1,n-k) 0];

    % The transmitted word T is ( M(x) * x^(n-k) ) / g(x)
    M_xnmk = polyMult(M,xnmk);
    [q r] = polyDiv(M_xnmk, g);
    T = polyAdd(M_xnmk,r);
end

